<!doctype html>
<html lang="en" class="fixed">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>编辑课程</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap-select.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">
    <!--    <link rel="stylesheet" href="-->
    <?php //xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?><!--">-->
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/metroStyle/metroStyle.css')) ?>"
          type="text/css">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        ul,li,ol,li{
            list-style: none;
        }
        body{
            background: #f4f4f4;
        }
        .addCourse{
            width: 900px;
            margin: 0 auto;
            background: #fff;
            padding-bottom: 10px;
        }
        .addCourse .addCourse-title{
            padding: 10px 20px;
            text-align: center;
        }
        .addCourse .addCourse-content .addCourse-cont h3{
            font-size: 12px;
            padding:12px;
            background: rgba(242,242,242,.5);
            margin-top: 0;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form{
            padding: 0 20px 20px;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row{
            margin-top: 20px;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row>div{
            display: inline-block;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row .layui-form-item label{
            font-size: 12px;
            padding: 6px;
            background: #FBFBFB;
            border: 1px #E8E8E8 solid;
            margin-left: 8px;
            width: initial;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row .form-group label{
            font-size: 12px;
            padding: 6px;
            background: #FBFBFB;
            border: 1px #E8E8E8 solid;
            margin-left: 8px;
            width: initial;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row .form-group input{
            border: 1px #e6e6e6 solid;
            border-radius: 2px;
            height: 34px;
            text-indent: 10px;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row p{
            float: left;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form .form-row textarea{
            resize: none;
            border-radius: 5px;
            border: 1px #ccc solid;
            text-indent: 10px;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form span{
            margin-left: 40px;
        }
        .addCourse .addCourse-content .addCourse-cont .cont-form span:nth-of-type(1){
            margin-left: 0;
        }
        .addCourse .addCourse-content .addCourse-cont .addCourse-btn{
            width: 100%;
            height: 40px;
            padding:0 20px;
        }
        .addCourse .addCourse-content .addCourse-cont .addCourse-btn .addCourse-btn-cont{
            float: right;
        }
        .layui-form-select .layui-input{
            padding-right: 0;
        }
        .bootstrap-select:not([class*="span"]):not([class*="col-"]):not([class*="form-control"]){
            width: 180px;
            height: 28px;
            background: #fff;
        }
        .btn{
            background: #fff;
            border:1px #e8e8e8 solid;
            border-radius: 2px;
            padding: 7px 12px;
        }
        .btn-default.active, .btn-default:active, .open>.dropdown-toggle.btn-default{
            background: #fff;
        }
        .btn-group-vertical>.btn, .btn-group>.btn:hover{
            background: #fff;
        }
    </style>
</head>

<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>
<div class="addCourse">
    <div class="addCourse-title">添加课程</div>
    <div class="addCourse-content">
        <div class="addCourse-cont">
            <form action="<?php xcho($saveUrl);?>" id="editList">
                <h3>基本信息</h3>
                <div class="cont-form">
                    <div class="form-row">
                        <div class="form-group">
                            <label class="control-label">课程名称：</label>
                            <input name="cname" id="cname" type="text">
                        </div>
                        <div class="form-group">
                            <label class="control-label" for="cyear">课程年份：</label>
                                <select name="cyear" id="cyear" class="selectpicker bla bla bli" multiple data-live-search="false">
                                    <?php foreach ($cyear as $aTmp) { ?>
                                        <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                    <?php } ?>
                                    </optgroup>
                                </select>
                        </div>
                        <!--<div class="layui-form-item">
                            <label class="layui-form-label">课程年份：</label>
                            <select name="cyear" id="cyear"  multiple="multiple" <?php /*xcho(in_array('cyear',$model)?'disabled':"")*/?>>
                                <option value=""></option>
                                <?php /*foreach ($cyear as $aTmp) { */?>
                                    <option value="<?php /*xcho($aTmp['dict_value']) */?>"><?php /*xcho($aTmp['cn_name']) */?></option>
                                <?php /*} */?>
                            </select>
                        </div>-->
                        <div class="form-group">
                            <label>课程周期：</label>
                            <select name="season" id="season" class="selectpicker bla bla bli" multiple data-live-search="false">
                                <?php foreach ($season as $aTmp) { ?>
                                    <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group">
                            <label>科目：</label>
                            <select name="csubject" id="csubject" class="selectpicker bla bla bli" data-live-search="false">
                                <?php foreach ($csubject as $aTmp) { ?>
                                    <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>年级：</label>
                            <select name="grade" id="grade" class="selectpicker bla bla bli" multiple data-live-search="false">
                                <?php foreach ($grade as $aTmp) { ?>
                                    <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>教材版本：</label>
                            <select name="edition" id="edition" class="selectpicker bla bla bli" multiple data-live-search="false">
                                <?php foreach ($edition as $aTmp) { ?>
                                    <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                <?php } ?>
                            </select>
                        </div>

                    </div>
                    <div class="form-row">
                        <div class="form-group">
                            <label>课程类别：</label>
                            <select name="ctype" id="ctype" class="selectpicker bla bla bli" data-live-search="false">
                                <?php foreach ($ctype as $aTmp) { ?>
                                    <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <h3>销售信息</h3>
                <div class="cont-form">
                    <div class="form-row">
                        <div class="form-group">
                            <label>价格：</label>
                            <input type="text" name="price" id="price" placeholder="" class="int">
                        </div>
                        <div class="form-group">
                            <label>总小时：</label>
                            <input type="text" name="duration" id="duration" placeholder="" class="int">
                        </div>
                        <div class="form-group">
                            <label>状态：</label>
                            <select name="signup_status" id="signup_status"  class="selectpicker bla bla bli" data-live-search="false">
                                <?php foreach ($signup_status as $aTmp) { ?>
                                    <option value="<?php xcho($aTmp['dict_value']) ?>"><?php xcho($aTmp['cn_name']) ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                </div>
                <h3>同步信息</h3>
                <div class="cont-form">
                    <div class="form-row">
                        <div class="form-group">
                            <label>官网课程ID：</label>
                            <input type="text" name="gw_id" id="gw_id" placeholder="" class="int">
                        </div>
                        <div class="form-group">
                            <label>官网课程名：</label>
                            <input type="text" name="gw_name" id="gw_name" placeholder="">
                        </div>
                        <div class="form-group">
                            <label>课程后台ID：</label>
                            <input type="text" name="ht_id" id="ht_id" placeholder="" class="int">
                        </div>
                    </div>
                    <div class="form-row">
                        <p>添加备注：</p>
                        <textarea name="remark" id="remark" cols="110" rows="3" placeholder="请输入备注"></textarea>
                    </div>
                    <input type="hidden" id="id" name="id" value="<?php xcho($iID);?>">
                    <div class="addCourse-btn">
                        <div class="addCourse-btn-cont">
                            <span class="layui-btn layui-btn-primary" id="cancel">取消</span>
                            <span class="layui-btn" id="submit">确定</span>
                        </div>
                    </div>
            </form>
            <input type="hidden" id="ajaxUrl" name="ajaxUrl" value="<?php xcho($ajaxUrl);?>">
            <input type="hidden" id="modelUrl" name="modelUrl" url="<?php xcho($modelUrl);?>">
        </div>
    </div>
</div>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui-mz-min.js')) ?>" charset="utf-8"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap-select.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layer-v3.0.3/layer/layer.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/ztree/js/jquery.ztree.core.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets/plugins/ztree/js/jquery.ztree.excheck.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets/plugins/ztree/js/jquery.ztree.exedit.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets/js/validate.js')) ?>"></script>
<script>
    $(window).on('load', function () {
        $('.selectpicker').selectpicker({
            'selectedText': 'cat',
            'noneSelectedText':'',
        });
        // $('.selectpicker').selectpicker('hide');
    });
    $(function () {
        window.onload = function(){
            $("span.pull-left").text("");
            layui.use(['form', 'jquery'], function(){
                var form = layui.form,
                    $ = layui.jquery;
                layui.selMeltiple($);
            });
            $("#grade").next("div").removeClass("layui-form-selected");
            var editId = $("input[name='id']").val(),
                editUrl = $("input[name='ajaxUrl']").val();
            $.ajax({
                url:editUrl,
                data:{
                    id:editId
                },
                type:'POST',
                dataType:'json',
                async:'false',
                success:function(data){
                    if(data['success'] == 1){
                        $.each(data['data'],function (sKey,mData) {
                            if(sKey != 'edition' && sKey != 'cyear' && sKey != 'grade' && sKey != 'season'){
                                if(sKey == 'csubject' || sKey == 'ctype' || sKey == 'signup_status'){
                                    //select添加selected属性
                                    $("#"+sKey).find("option[value='"+mData+"']").attr("selected",true);
                                    //select选中项显示
                                    var selectVal;
                                    $($("#"+sKey).find("option:selected")).each(function(){
                                        selectVal = $(this).text();
                                        $("#"+sKey).next("div").find("span.pull-left").append(selectVal);
                                        //选中项标示
                                        $($("#"+sKey).next("div").find("li")).each(function(n,val){
                                            if($(this).find("a").text() == selectVal){
                                                $(this).addClass("selected");
                                            }
                                        })
                                    })
                                }else{
                                    $("#"+sKey).attr('value',mData);
                                }
                            }else{
                                //select添加selected属性
                                $.each(mData,function (i,t) {
                                    $("#"+sKey).find("option[value='"+t+"']").attr("selected",true);
                                })
                                //select选中项显示
                                var selectVal;
                                $($("#"+sKey).find("option:selected")).each(function(){
                                    selectVal = $(this).text();
                                    $("#"+sKey).next("div").find("span.pull-left").append(selectVal+",");
                                    //选中项标示
                                    $($("#"+sKey).next("div").find("li")).each(function(n,val){
                                        if($(this).find("a").text() == selectVal){
                                            $(this).addClass("selected");
                                        }
                                    })
                                })

                            }
                        })
                    }
                }
            })

            //获取不可写数据
            $.ajax({
                url:$("#modelUrl").attr('url'),
                data:{},
                type:'POST',
                dataType:'json',
                success:function(data){
                    $.each(data,function (iKey,sVal) {
                        $("#"+sVal).attr('disabled','disabled');
                    })
                }
            })
        }
        //提交表单
        $("#submit").click(function(){
            var isContine = validateF();
            if(!isContine) return false;
            $(".hidden_area").remove();
            var arrCyear = [],arrSeason = [],arrGrade = [],arrEdition = [];
            //年份
            /*$($("#cyear").next("div").find("li")).each(function(){
                if($(this).hasClass("layui-this")){
                    var cyearVal = $(this).attr("lay-value");
                    arrCyear.push(cyearVal);
                }
            })*/
            $($("#cyear").find("option:selected")).each(function(){
                    var cyearVal = $(this).attr("value");
                    arrCyear.push(cyearVal);
            })
            console.log(arrCyear);
            //周期
            $($("#season").find("option:selected")).each(function(){
                    var seasonVal = $(this).attr("value");
                    arrSeason.push(seasonVal);
            })
            //年级
            $($("#grade").find("option:selected")).each(function(){
                    var gradeVal = $(this).attr("value");
                    arrGrade.push(gradeVal);
            })
            //版本
            $($("#edition").find("option:selected")).each(function(){
                    var editionVal = $(this).attr("value");
                    arrEdition.push(editionVal);
            })
            //科目
            var csubject;
            $( $("#csubject").find("option:selected")).each(function(){
                    csubject = $(this).attr("value");
            })
            //课程类别
            var ctype;
            $( $("#ctype").find("option:selected")).each(function(){
                    ctype = $(this).attr("value");
            })
            //状态
            var signup_status;
            $( $("#signup_status").find("option:selected")).each(function(){
                    signup_status = $(this).attr("value");
            })
            var addUrl = $("#editList").attr("action"),
                cname = $('input[name="cname"]').val(),
                price = $('input[name="price"]').val(),
                duration = $('input[name="duration"]').val(),
                gw_id = $('input[name="gw_id"]').val(),
                gw_name = $('input[name="gw_name"]').val(),
                ht_id = $('input[name="ht_id"]').val(),
                remark = $('#remark').val();
            $.ajax({
                url:addUrl,
                data:{
                    id:$("#id").val(),
                    cname:cname,
                    cyear:arrCyear,
                    season:arrSeason,
                    csubject:csubject,
                    grade:arrGrade,
                    edition:arrEdition,
                    ctype:ctype,
                    price:price,
                    duration:duration,
                    signup_status:signup_status,
                    gw_id:gw_id,
                    gw_name:gw_name,
                    ht_id:ht_id,
                    remark:remark
                },
                type:'POST',
                dataType:'json',
                success:function(data){
                    if(data.success==1){
                        $("#editList").submit();
                        $("#cancel").trigger("click");
                    }else{
                        $.each(data.errors,function (sKey,aVal) {
                            $('#'+sKey).after("<span class='hidden_area' style='color: red;padding-top: 5px;'>"+aVal['message']+"</span>");
                        })
                    }
                }
            })
        })
        //关闭编辑课程
        $("#cancel").on("click",function () {
            window.history.back();
            //window.parent.$('#index_tabs').tabs('close','编辑课程');
        })
    });
</script>
<?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>
<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
